package 多态;

/**
 * @Author 12629
 * @Description：
 */
class Shape {
    //属性....

    public void draw() {
        System.out.println("画图形！");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("♦");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("●");
    }
}
class Triangle extends Shape{
    @Override
    public void draw() {
        System.out.println("△");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("❀");
    }
}
public class Test2 {

    public static void drawMap2( ) {
         //圆  矩形   圆  矩形  花
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};

        for (String shape : shapes) {
            if (shape.equals("cycle")) {
                cycle.draw();
            } else if (shape.equals("rect")) {
                rect.draw();
            } else if (shape.equals("flower")) {
                flower.draw();
            }
        }
    }

    public static void drawMap3( ) {
        //圆  矩形   圆  矩形  花
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        Shape[] shapes = {rect,cycle,rect,cycle,flower};

        for (Shape shape : shapes) {
            //当前shape引用的对象重写draw方法就调用，没有就调用Shape自己的
            shape.draw();
        }
    }

    public static void main(String[] args) {
        drawMap3();
    }

    public static void drawMap(Shape shape) {
        shape.draw();
    }

    public static void main2(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Triangle triangle = new Triangle();
        Flower flower = new Flower();
        drawMap(rect);
        drawMap(cycle);
        drawMap(triangle);
        drawMap(flower);
    }
}
